package com.yanqu.road.dao.impl.activity.fellingtrees;

import com.yanqu.road.dao.db.DbNameStrategy;
import com.yanqu.road.dao.impl.TempDao;
import com.yanqu.road.entity.activity.fellingtrees.config.FellingTreesLevelConfig;

import java.math.BigInteger;
import java.sql.CallableStatement;
import java.sql.ResultSet;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

public class FellingTreesLevelConfigDaoImpl extends TempDao {

    private static String getFellingTreesLevelConfigSql = "select * from `t_s_activity_ftrees_level` where `activityId`=?";

    public Map<Integer, FellingTreesLevelConfig> getFellingTreesLevelConfigMap(int activityId) {
        Map<Integer, FellingTreesLevelConfig> map = new ConcurrentHashMap<>();
        ResultSet rs = null;
        CallableStatement call = null;
        try {
            getDb().setConnName(DbNameStrategy.getServerDb());
            call = getDb().getConnection().prepareCall(getFellingTreesLevelConfigSql);
            int i = 1;
            call.setInt(i++, activityId);
            rs = call.executeQuery();
            while (rs.next()) {
                FellingTreesLevelConfig fellingTreesLevelConfig = new FellingTreesLevelConfig();
                fellingTreesLevelConfig.setActivityId(rs.getInt("activityId"));
                fellingTreesLevelConfig.setId(rs.getString("id"));
                fellingTreesLevelConfig.setLevel(rs.getInt("level"));
                fellingTreesLevelConfig.setHp(new BigInteger(rs.getString("hp")));
                fellingTreesLevelConfig.setGold(new BigInteger(rs.getString("gold")));
                fellingTreesLevelConfig.setDropLevel(rs.getInt("dropLevel"));
                fellingTreesLevelConfig.setDropFirstWeapon(rs.getInt("dropFirstWeapon"));
                fellingTreesLevelConfig.setDropWeaponPro(rs.getString("dropWeaponPro"));
                fellingTreesLevelConfig.setDropMedicialMaterial(rs.getInt("dropMedicialMaterial"));
                fellingTreesLevelConfig.setDropSpiritBead(rs.getInt("dropSpiritBead"));
                fellingTreesLevelConfig.setWeaponAtt(new BigInteger(rs.getString("weaponAtt")));
                fellingTreesLevelConfig.setSellGold(new BigInteger(rs.getString("sellGold")));
                fellingTreesLevelConfig.setStrengthGold(new BigInteger(rs.getString("strengthGold")));
                fellingTreesLevelConfig.setAutoSellWeaponLevel(rs.getString("autoSellWeaponLevel"));
                fellingTreesLevelConfig.setDropMoonStone(rs.getInt("dropMoonStone"));
                map.put(fellingTreesLevelConfig.getLevel(), fellingTreesLevelConfig);
            }
        } catch (Exception e) {
            logger.error(Thread.currentThread().getStackTrace()[1].getMethodName() + ":", e);
        } finally {
            getDb().closeConnection(call, rs);
        }
        return map;
    }

}
